package IO.g1;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Random;

public class aufgabe1 {

	public static void main(String[] args) {
		
		char sep = File.separatorChar;
		
		new File("aufgabe1").mkdir();
		for(int i = 1; i <= 200; i++){
			new File("aufgabe1"+sep+i).mkdir();
		}
		
		Random r = new Random();
		int i = 0;
		while(i < 5){
			int ordner = r.nextInt(200)+1;
			try {
				new File("aufgabe1"+sep+ordner+sep+"file"+i+".bmp").createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
			i++;
		}
		
		for(int j = 1; j <= 200; j++){
			File dir = new File("aufgabe1"+sep+j);
			File[] subfiles = dir.listFiles(new FilenameFilter(){

				@Override
				public boolean accept(File dir, String name) {
					return new File(dir, name).isFile() 
							&& name.toLowerCase().endsWith(".bmp");
				}
			});
			
			for(File f: subfiles){
				
				System.out.println("Ordner:" +dir.getName());
				System.out.println("Umbennenung erfolgreich? "
						+ f.renameTo(new File(f.getAbsolutePath().replaceAll("bmp", "txt"))));
			}
		}
	}

}
